<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        
        h1{
                color:saddlebrown;
                font-size: 100px;
                text-align: center;
                margin-top: 20px;
            }
        
    </style>
</head>
<body>
    <body>
        <button id="start">开始</button>
        <button id="end">结束</button>
        <h1 id="txt">黄嘉鑫</h1>
        <script>
            var start=document.getElementById('start')
            var end=document.getElementById('end')
            var txt=document.getElementById('txt');
            var timer;
            var list=['快乐','悲伤','愤怒','悲哀','皇帝','天地'];
            console.log(list[0]);
            console.log(list.length)
            start.onclick=function(){
                clearInterval(timer)
               timer=setInterval(function(){
                    var n=parseInt(Math.random()*list.length);
                    txt.innerHTML=list[n];
                },100)
            }
            end.onclick=function(){
                clearInterval(timer);
                // txt.innerHTML=list[list.length-1];
            }
        </script>
    
</body>
    
</body>
</html>